package eom.example.elasticsearch.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import eom.example.elasticsearch.domain.Student;
import eom.example.elasticsearch.service.StudentService;
import eom.example.elasticsearch.mapper.StudentMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
*
*/
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student>
implements StudentService{

    @Override
    public IPage<Student> getPage(Integer page, Integer size, String keyword) {
        LambdaQueryWrapper<Student> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        if(StringUtils.isNotBlank(keyword)){
            lambdaQueryWrapper.like(Student::getStuAddress,keyword);
            lambdaQueryWrapper.or().like(Student::getStuName,keyword);
            lambdaQueryWrapper.or().like(Student::getStuAge,keyword);
            lambdaQueryWrapper.or().like(Student::getStuMobile,keyword);
            lambdaQueryWrapper.or().like(Student::getStuNote,keyword);
        }
        Page page1=new Page(page,size);
        lambdaQueryWrapper.orderByDesc(Student::getCreateDate);
        IPage<Student> studentIPage=this.baseMapper.selectPage(page1,lambdaQueryWrapper);
        return studentIPage;
    }
}
